package org.jeecg.modules.xl.kuaimai.service;

import cn.hutool.core.date.StopWatch;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.xl.kuaimai.KuaimaiAPIConfig;
import org.quartz.*;

import java.util.Map;

/**
 * 快麦token刷新
 *
 * @author deco
 * @create 2025-01-06
 */
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
@Slf4j
public class KMTokenRefreshJob implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        try {
            log.info(" --- 同步任务调度开始 --- ");
            StopWatch stopWatch = new StopWatch();
            stopWatch.start();

            Map<String, String> params = Maps.newHashMap();
            params.put("refreshToken","7106aa68d0a9440d8b090894cf7962cb");
            Map<String, String> refreshPara = KuaimaiAPIConfig.getKuaiMaiAPIPublicParam("open.token.refresh",params);
            String firstPageStr = HttpUtil.post("https://gw3.superboss.cc/router", JSON.toJSONString(refreshPara));

            System.out.println(firstPageStr);
            stopWatch.stop();
            //测试发现 每5秒执行一次
            log.info(" --- 执行完毕，时间："+ stopWatch.getTotalTimeMillis());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }


    }
}
